package com.sunshine.domain.handler.subject;

import com.sunshine.common.enums.SubjectInfoEnum;
import com.sunshine.domain.convert.SubjectRadioInfoConvert;
import com.sunshine.domain.entity.SubjectInfoBO;
import com.sunshine.infra.basic.entity.SubjectRadio;
import com.sunshine.infra.basic.service.SubjectRadioService;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @description: 单选题
 * @version 1.0
 * @Author 夏百友
 * @Date 2025/11/12 19:29
 */

public class RadioTypeHandler implements subjectTypeHandler{

    @Resource
    private SubjectRadioService subjectRadioService;


    @Override
    public SubjectInfoEnum getHandlerType() {
        return SubjectInfoEnum.RADIO;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        //单选题目插入
        List<SubjectRadio> subjectRadiolist = new LinkedList<>();
        subjectInfoBO.getOptionlist().forEach(item -> {

            SubjectRadio subjectRadio = SubjectRadioInfoConvert.INSTANCE.convertBoToInfo(item);
            subjectRadio.setSubjectId(subjectInfoBO.getId());
            subjectRadiolist.add(subjectRadio);
        });

        subjectRadioService.batchinsert(subjectRadiolist);
    }
}
